package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.*;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    Page<Orders> conditionSerch(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select count(*) from orders where status = 1")
    List<Orders> getstatics();


    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer toBeConfirmed);

    @Select(("select id from orders where number = #{number}"))
    Integer getOrderid(String orderNumber);


    @Update(("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus}," +
            "checkout_time = #{checkOutTime}" +
            " where id = #{orderid}"))
    void updateOrdersStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime checkOutTime, Integer orderid);

    @Update("update orders set  status = 3 where id = #{id}")
    void update(OrdersConfirmDTO ordersConfirmDTO);


    @Update("update orders set status = 4 , delivery_status = 1 where id = #{id}")
    void delivery(Long id);


    @Update("update orders set delivery_time = #{checkOutTime},status = 5 where id = #{id}")
    void finish(Long id, LocalDateTime checkOutTime);

    @Update("update orders set status = 6 ,cancel_reason = #{cancelReason} where id = #{id} ")
    void cancel(OrdersCancelDTO ordersCancelDTO);

    @Update("update orders set status = 7,rejection_reason = #{rejectionReason} where id = #{id}")
    void rejection(OrdersRejectionDTO ordersRejectionDTO);

    @Select("select * from orders where id = #{id}")
    Orders detail(Long id);

    @Select("select * from order_detail where order_id = #{orderid}")
    List<OrderDetail> getOrderDetail(Integer orderid);

    @Select("select id from orders where user_id = #{userId}")
   Page<Long> getId(Long userId);

    @Select("select * from orders where  id = #{orderId}")
    Orders getAllorders(Long orderId);

    @Select("select * from order_detail where order_id = #{id}")
    List<OrderDetail> getdetatil(Long id);

    @Select("select * from orders where id = #{id}")
    Orders getOrder(Long id);

    @Update("update orders set status = #{status} where number = #{number}")
    void change(Orders orders);

    @Select("select * from orders where number = #{outTradeNo}")
    Orders getnNmber(String outTradeNo);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where status = #{pendingPayment}   ")
    List<Orders> getTimeOrder( Integer pendingPayment);


    void updateOrders(Orders orders);

    @Select("select * from orders where status = #{deliveryInProgress}")
    List<Orders> getDeliver_process(Integer deliveryInProgress);

    Double getAllmountBydate(Map map);

    Integer getUser(Map map);

    Integer getOrdercount(Map map);

    List<GoodsSalesDTO> getTop10(LocalDateTime beginTime, LocalDateTime endTime);
}
